package com.bdqn.repository;

import com.bdqn.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserRepository extends JpaRepository<User,Long>, JpaSpecificationExecutor<User> {

     List<User> findByUsrNameLike(String usrName);

     List<User> findByUsrNameAndUsrPassword(String usrName, String usrPassword);

     List<User> findByUsrName(String userName);

    @Query("select u from User u where u.usrRoleId=?1")
    Page<User> findPageByUsrRoleId(Long roleId, Pageable pageable);

    @Query(value = "select * from sys_user where usr_role_id=?1", nativeQuery = true)
    List<User> findByRoleIdNative(Long roleId);

    @Query("select u from User u where u.usrRoleId=:roleId")
    List<User> findByRoleIdParam(@Param("roleId") Long roleId);

    @Transactional(timeout = 10)
    @Modifying
    @Query("update User u set u.usrName=?1 where u.usrId=?2")
    int modifyNameById(String usrName, Long usrId);





}

